
utility ExExporter "ExExporter" width:162 height:351
(
	
	global triOrder = #(2,1,3)
	global gFilestream
	global gExportBakedCoordinates =  not false
	global gWriteObjects = true
	global gBSPCleanup = true
	global gWorldFilename = (getFilenameFile maxFileName) as string
	global gProjectName = undefined
	global gRollout = undefined
	global gMaxDepth = undefined
	global gMaxTriangles = undefined
		
	global totalInnerNodesWritten = 0
	global totaLeavesWritten = 0
	global gNodeCount = 0
	global gVerboseOutput = not true
	global gRoot = undefined
		
	include "ee_util.ms"
	include "file_util.ms"
	include "material_export.ms"
	include "mesh_util.ms"
	include "model_export.ms"
	include "bsp_export.ms"
	include "physics_export.ms"
	   
	rollout gRollout "ExExport" width:162 height:444
	(
		GroupBox grp1 "Static Model Export" pos:[2,82] width:156 height:95
		button expStatMesh "Export Mesh" pos:[34,104] width:88 height:31
		dropdownList ddl2 "Project Name" pos:[9,5] width:142 height:40 items:#("ChuckDingo", "ExplosionDemo", "TunnelDemo", "FireDemo", "Atlantis")
		GroupBox grp2 "Level" pos:[2,215] width:156 height:205
		button expStaticPhy "Export Physics" pos:[34,139] width:88 height:31
		button expCompileWorld "Compile" pos:[18,372] width:115 height:31
		edittext expWorldName "Filename" pos:[13,233] width:130 height:18 text:gWorldFilename
		spinner maxDepth "Tree Depth     " pos:[19,280] width:130 height:16 range:[1,8,gMaxDepth] type:#integer scale:1  
		spinner spn2 "Leaf Triangles " pos:[19,304] width:130 height:16 range:[1,10000,gMaxTriangles] type:#integer scale:1
		label lbl1 "Maximums:" pos:[11,261] width:67 height:18
		fn updateExportProject =
		(
			gProjectName	= ddl2.items[ddl2.selection] + "\\"
		)

		checkbutton expStatBakedCoords "Ambient Occlusion" pos:[10,56] width:115 height:18 checked:gExportBakedCoordinates
		checkbutton ckb8 "Write Objects" pos:[20,328] width:115 height:18 checked:gWriteObjects
		checkbutton ckb11 "Clean up" pos:[20,350] width:115 height:18 checked:gBSPCleanup
		on expStatMesh pressed do
		(
			updateExportProject()			
			exportStaticMesh()
		)
		on expStaticPhy pressed do
		(
			updateExportProject()
			exportStaticPhys()
		)
		on expCompileWorld pressed do
		(
			updateExportProject()
			gWorldFilename = expWorldName.text
			
			compileWorld()
		)
		on maxDepth changed val do
		(
			gMaxTriangles = (val as integer)
			print gMaxTriangles
		)
		on spn2 changed val do
		(
			gMaxDepth = (val as integer)
			print gMaxDepth
		)
		on expStatBakedCoords changed state do
		(
			if (state == true) then
				gExportBakedCoordinates = true
			else
				gExportBakedCoordinates = false
		)
		on ckb8 changed state do
		(
			if (state == true) then
				gWriteObjects = true
			else
				gWriteObjects = false
		)
		on ckb11 changed state do
		(
			if (state == true) then
				gBSPCleanup = true
			else
				gBSPCleanup = false
		)
	)
	
		local dlgBox = undefined
	on ExExporter open do
	(
		gMaxDepth = 4
		gMaxTriangles = 11
		dlgBox = newRolloutFloater  "ExExport" 180 440 10 100
		addRollout gRollout dlgBox
	)
	on ExExporter close do
	(
		closeRolloutFloater  dlgBox
	)

)

 
